package cn.org.eshow.webapp.action;

import cn.org.eshow.bean.query.ProductOrderSummaryQuery;
import cn.org.eshow.common.page.Page;
import cn.org.eshow.model.ProductOrderSummary;
import cn.org.eshow.service.ProductOrderSummaryManager;
import cn.org.eshow.util.PageUtil;
import org.apache.struts2.convention.annotation.AllowedMethods;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Results({@Result(name = "input", location = "/add"),
        @Result(name = "list", type = "redirect", location = "/productOrderSummary/"),
        @Result(name = "success", type = "redirect", location = "/view/${id}"),
        @Result(name = "redirect", type = "redirect", location = "${redirect}")})
@AllowedMethods({"check", "search", "view"})
public class ProductOrderSummaryAction extends BaseAction {

    private static final long serialVersionUID = 1L;

    @Autowired
    private ProductOrderSummaryManager productOrderSummaryManager;
    private List<ProductOrderSummary> productOrderSummarys;
    private ProductOrderSummary productOrderSummary = new ProductOrderSummary();
    private ProductOrderSummaryQuery query = new ProductOrderSummaryQuery();

    /**
     * 搜索列表
     */
    public String search() {
        Page<ProductOrderSummary> page = productOrderSummaryManager.search(query);
        productOrderSummarys = page.getDataList();
        saveRequest("page", PageUtil.conversion(page));
        saveRequest("query", query);
        return LIST;
    }

    public String view() {
        if (id != null) {
            productOrderSummary = productOrderSummaryManager.get(id);
        } else {
            return INDEX;
        }
        return NONE;
    }

    public String check() {
        productOrderSummary = productOrderSummaryManager.check(query);
        return LIST;
    }

    public List<ProductOrderSummary> getProductOrderSummarys() {
        return productOrderSummarys;
    }

    public void setProductOrderSummarys(List<ProductOrderSummary> productOrderSummarys) {
        this.productOrderSummarys = productOrderSummarys;
    }

    public ProductOrderSummary getProductOrderSummary() {
        return productOrderSummary;
    }

    public void setProductOrderSummary(ProductOrderSummary productOrderSummary) {
        this.productOrderSummary = productOrderSummary;
    }

    public ProductOrderSummaryQuery getQuery() {
        return query;
    }

    public void setQuery(ProductOrderSummaryQuery query) {
        this.query = query;
    }
}